<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function diffDate(d1, d2) {
        d1 = new Date(d1.replace(/-/g, '/')) //结束时间
        d2 = new Date(d2.replace(/-/g, '/')) //开始时间

        if (d1.getTime() > d2.getTime()) {
            return {status: false}
        }
        console.log(d1, d2)
        let Y1 = d1.getFullYear() // 结束年份
        let Y2 = d2.getFullYear() // 开始年份

        let M1 = d1.getMonth() + 1 // 结束月份
        let M2 = d2.getMonth() + 1 // 开始月份

        let diff_day1 = Math.ceil((d1 - new Date(d1.getFullYear().toString())) / (24 * 60 * 60 * 1000)) + 1;
        let diff_day2 = Math.ceil((d2 - new Date(d2.getFullYear().toString())) / (24 * 60 * 60 * 1000)) + 1;

        return {
            year: Y2 - Y1,
            month: M2 - M1,
            day: diff_day2 - diff_day1,
            status: true
        }
    }

    let s1 = "2023-02-15"
    let s2 = "2023-03-19"

    console.log(diffDate(s1, s2))
</script>
</body>
</html>